<?php



namespace App\Services\Member\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use App\Services\Member\Models\User;

class UserProfile extends Model
{
    use SoftDeletes;

    protected $table = 'user_profiles';

    protected $fillable = [
        'user_id', 'real_name', 'gender', 'age', 'birthday', 'profession_tag', 'address','is_public',
        'graduated_school', 'diploma',
        'id_number', 'id_frontend_thumb', 'id_backend_thumb', 'id_hand_thumb','bg_image'
    ];

    public const EDIT_COLUMNS = [
        'real_name', 'gender', 'age', 'birthday', 'profession_tag', 'address','is_public',
        'graduated_school', 'diploma',
        'id_number', 'id_frontend_thumb', 'id_backend_thumb', 'id_hand_thumb','bg_image','is_fulltime','work_years','category_id'
    ];

    public function setProfessionTagAttribute($professionTag)
    {
         if (is_array($professionTag) && count($professionTag) > 0 ){

             $this->attributes['profession_tag']= implode("|", $professionTag);
         }else{
             $this->attributes['profession_tag'] ='';
         }

    }
    public function getProfessionTagAttribute($professionTag)
    {
        if (strpos($professionTag, "|") !== false){
            return  explode("|", $professionTag);
        }elseif (strlen($professionTag)>0){

            return  [$professionTag];
        }
        else{
            return  $professionTag;
        }

    }
    public function user()
    {
        return $this->belongsTo(User::class, 'user_id');
    }

}
